"""
闭包
1. 外函数 -- 内函数
2. 外函数返回内函数
3. 内函数引用外函数的变量
nonlocal: 在闭包中修改外函数的参数
"""


def outer():
    outer = 10

    def inner():
        nonlocal outer
        outer = 9
        print("inner:", outer)
        return

    return inner


res = outer()
res()

"""
计时器装饰器
"""
import time


def Timer(func):
    start = time.time()

    def warp(*a, **kwargs):
        func(*a, **kwargs)
        end = time.time()
        print("time:", end - start)

        return

    return warp


@Timer
def foo():
    for i in range(1000000000):
        pass


foo()
